<script setup>
import { ref, computed } from 'vue'
import ChatWidget from '../components/ChatWidget.vue'
import { injectLanguage } from '../utils/language-store.js'

const { t } = injectLanguage()

// 联系信息数据 - 使用计算属性动态获取翻译
const contactInfo = computed(() => [
  {
    icon: '📍',
    title: t('contact.info.addressTitle'),
    content: t('contact.info.address')
  },
  {
    icon: '📞',
    title: t('contact.info.phoneTitle'),
    content: t('contact.info.phone')
  },
  {
    icon: '✉️',
    title: t('contact.info.emailTitle'),
    content: t('contact.info.email')
  }
])

// 表单数据
const formData = ref({
  name: '',
  email: '',
  phone: '',
  message: ''
})



// 提交表单
const submitForm = () => {
  console.log('表单提交:', formData.value)
  // 这里可以添加实际的表单提交逻辑
  alert('感谢您的留言，我们会尽快与您联系！')
  
  // 重置表单
  formData.value = {
    name: '',
    email: '',
    phone: '',
    message: ''
  }
}
</script>

<template>
  <div class="contact">
    <!-- 联系我们头部 -->
    <section class="contact-header">
      <div class="container">
        <h1 v-text="t('contact.pageTitle')"></h1>
        <p v-text="t('contact.subtitle')"></p>
      </div>
    </section>

    <!-- 联系信息 -->
    <section class="contact-info">
      <div class="container">
        <div class="info-cards">
          <div 
            class="info-card" 
            v-for="(info, index) in contactInfo" 
            :key="index"
          >
            <div class="info-icon" v-text="info.icon"></div>
            <h3 v-text="index === 0 ? t('contact.info.addressTitle') : index === 1 ? t('contact.info.phoneTitle') : t('contact.info.emailTitle')"></h3>
            <p v-text="index === 0 ? t('contact.info.address') : index === 1 ? t('contact.info.phone') : t('contact.info.email')"></p>
          </div>
        </div>
      </div>
    </section>

    <!-- 联系表单 -->
    <section class="contact-form">
      <div class="container">
        <h2 v-text="t('contact.sendMessage')"></h2>
        <form @submit.prevent="submitForm">
          <div class="form-group">
            <input 
              v-model="formData.name" 
              type="text" 
              :placeholder="t('contact.namePlaceholder')" 
              required
            >
          </div>
          <div class="form-group">
            <input 
              v-model="formData.email" 
              type="email" 
              :placeholder="t('contact.emailPlaceholder')" 
              required
            >
          </div>
          <div class="form-group">
            <input 
              v-model="formData.phone" 
              type="tel" 
              :placeholder="t('contact.phonePlaceholder')"
            >
          </div>
          <div class="form-group">
            <textarea 
              v-model="formData.message" 
              :placeholder="t('contact.messagePlaceholder')" 
              rows="6" 
              required
            ></textarea>
          </div>
          <button type="submit" class="submit-btn" v-text="t('contact.sendButton')"></button>
        </form>
      </div>
    </section>

    <!-- 在线客服组件 -->
    <ChatWidget />
  </div>
</template>

<style scoped>
.contact {
  font-family: 'Arial', sans-serif;
}

.contact-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 100px 0;
  text-align: center;
  margin-bottom: 3rem;
  border-radius: 0 0 30px 30px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

.contact-header h1 {
  font-size: 3.5rem;
  margin-bottom: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.contact-header p {
  font-size: 1.3rem;
  margin-bottom: 2.5rem;
  opacity: 0.95;
  max-width: 700px;
  margin-left: auto;
  margin-right: auto;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* 联系信息样式 */
.info-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2.5rem;
  margin-bottom: 5rem;
}

.info-card {
  background: white;
  border-radius: 20px;
  padding: 2.5rem;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  text-align: center;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.info-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.12);
  border-color: rgba(102, 126, 234, 0.2);
}

.info-icon {
  font-size: 3rem;
  margin-bottom: 1.5rem;
}

.info-card h3 {
  font-size: 1.7rem;
  margin-bottom: 1.2rem;
  color: #333;
  font-weight: 700;
}

.info-card p {
  color: #666;
  line-height: 1.7;
  font-size: 1.1rem;
}

/* 联系表单样式 */
.contact-form {
  background-color: #f9f9f9;
  padding: 50px 0;
}

.contact-form h2 {
  text-align: center;
  font-size: 2.8rem;
  margin-bottom: 3.5rem;
  color: #333;
  position: relative;
}

.contact-form h2::after {
  content: '';
  display: block;
  width: 80px;
  height: 4px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  margin: 1rem auto;
  border-radius: 2px;
}

form {
  max-width: 700px;
  margin: 0 auto;
}

.form-group {
  margin-bottom: 1.8rem;
}

form input,
form textarea {
  width: 100%;
  padding: 15px 20px;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  font-size: 1.1rem;
  transition: all 0.3s ease;
  background: white;
}

form input:focus,
form textarea:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

form textarea {
  resize: vertical;
  min-height: 150px;
}

.submit-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 15px 40px;
  font-size: 1.2rem;
  font-weight: 600;
  border-radius: 30px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: block;
  margin: 2rem auto 0;
  box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.submit-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.6);
}

@media (max-width: 768px) {
  .contact-header {
    padding: 6rem 1.5rem;
  }
  
  .contact-header h1 {
    font-size: 2.5rem;
  }
  
  .contact-header p {
    font-size: 1.1rem;
  }
  
  .container {
    padding: 0 1.5rem;
  }
  
  .info-cards {
    grid-template-columns: 1fr;
    gap: 2rem;
  }
  
  .contact-form h2 {
    font-size: 2.2rem;
  }
  
  form {
    padding: 0 1rem;
  }
}
</style>